package com.csii.activiti.server.abstraction.ipml;

import cn.hutool.core.collection.CollUtil;
import com.csii.activiti.server.abstraction.entity.ActUser;
import com.csii.activiti.server.abstraction.service.ActUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class ActUserServiceImpl implements ActUserService {

    private List<ActUser> users = new ArrayList<>();

    {
        users.add(new ActUser("zhou","周"));
        users.add(new ActUser("zhou1","周1"));
        users.add(new ActUser("zhou2","周2"));
        users.add(new ActUser("zhou3","周3"));
        users.add(new ActUser("zhou4","周4"));
        users.add(new ActUser("zhou5","周5"));
        users.add(new ActUser("zhou6","周6"));
        users.add(new ActUser("zhou7","周7"));
        users.add(new ActUser("zhou8","周8"));
        users.add(new ActUser("zhou9","周9"));
        users.add(new ActUser("zhou10","周10"));
        users.add(new ActUser("li1","李1"));
    }

    @Override
    public List<ActUser> queryUserLikeUsernameOrNickname(String usernameOrNickname) {
        return users.stream().filter(item-> item.getUsername().contains(usernameOrNickname) || item.getNickname().contains(usernameOrNickname)).collect(Collectors.toList());
    }

    @Override
    public List<ActUser> queryUserByRoleCode(String roleCode) {
        if (roleCode.equals("role13")){
            return null;
        }
        String lastChar = String.valueOf(roleCode.charAt(roleCode.length() - 1));
        if ("e".equals(lastChar)){
            lastChar = "u";
        }
        String finalLastChar = lastChar;

        return users.stream().filter(item -> item.getUsername().endsWith(finalLastChar)).collect(Collectors.toList());
    }

    @Override
    public List<ActUser> queryUserByUsernames(Set<String> usernames) {
        return users.stream().filter(item->usernames.contains(item.getUsername())).collect(Collectors.toList());
    }

    @Override
    public List<ActUser> queryHisLeadershipByUsername(String username) {
        return CollUtil.newArrayList(new ActUser("li1","李1"));
    }
}
